package com.man.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.man.LogicService.loginService;
import com.man.bean.AdminMan;
import com.man.dao.AdminDao;



/**
 * Servlet implementation class RegistServlet
 */
@WebServlet("/Login")
public class LoginServlet extends HttpServlet {
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		
		String name = request.getParameter("account");//获取账号
		String password = request.getParameter("password");//获取密码
		String pow = request.getParameter("pow");//获取权限
		AdminMan adminman = new AdminMan(name, password, pow);
		int num = new AdminDao().showAdmin(adminman);
		if(num==0) {
			request.getSession().setAttribute("admin", "账号密码错误请检查");
			response.sendRedirect("Login.jsp");
		}else {
			request.getSession().setAttribute("account", name);
			request.getSession().setAttribute("pow", pow);
			if(pow.equals("1")) {
			
				response.sendRedirect("jspPage/man.jsp");
			}else {
		
				response.sendRedirect("jspPage/peo.jsp");
				
			}
		}
	}

}
